package com.example.diary;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.Button;

/**
 * @author zengzl
 * @create 2021/11/22 10:51 上午
 */
public class MyDiaryButton extends Button {

    public MyDiaryButton(Context context) {
        super(context);
    }

    public MyDiaryButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyDiaryButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public MyDiaryButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }


    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        ColorDrawable defaultBgDrawable = new ColorDrawable(Color.WHITE);
        this.setAllCaps(false);
        this.setBackground(defaultBgDrawable);
        this.setTextColor(ColorTools.getColorStateList(getContext(), R.color.button_default_text_color));
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            this.setStateListAnimator(null);
        }
        // 先不管ScreenHelper
//        this.setMinimumWidth(ScreenHelper.dpToPixel(getContext().getResources(), 80));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
    }
}
